/**
 * Copyright 2007 American Well Systems
 * All rights reserved.
 *
 * It is illegal to use, reproduce or distribute
 * any part of this Intellectual Property without
 * prior written authorization from American Well.
 */
package com.primera.geneiousplugin.ui;

import java.awt.Toolkit;
import java.util.HashMap;
import java.util.Map;

import javax.swing.Icon;
import javax.swing.ImageIcon;

/**
 * Current impl of externalized resources.
 * TODO resource file
 * @author Rich O'Connell
 */
public class ResourceManager {

	private static Map<String, String> messages = new HashMap<String, String>();
	private static Map<String, Icon> icons = new HashMap<String, Icon>();

	private static final String MSG_HELP_ME = "<p>Execute a Python script against a selection of documents.</p>" +
		"<p>Specify:</p>" +
		"<ol>" +
			"<li>The command used to run Python</li>" +
			"<li>The path of the script to be run</li>" +
			"<li>Any additional paramters to be passed to the Python runtime</li>" +
			"<li>The name of the result folder.  This folder will be created relative to the location of the first selected input document.</li>" +
		"</ol>" +
		"<p>Make sure Python is in your user path.</p>" +
		"<p>The Python script will be given the selected documents in Geneious XML format, " +
		"piped to the standard input stream.  " +
		"The script can attempt to create new documents by writing " +
		"them to the standard output in Geneious XML format.</p>";

	static {
		messages.put("dialog.complete.title", "Operation finished.");
		messages.put("dialog.complete.ok", "Done");
		messages.put("dialog.complete.out", "Python output:");
		messages.put("dialog.complete.created", "Documents created");
		messages.put("help.html", MSG_HELP_ME);
		messages.put("toolbar.name", "Run Py");
		messages.put("action.description", "run python description");
		messages.put("action.name", "Run Py...");

		icons.put("py.small", icon("/smallIcon.png"));
		icons.put("py.large", icon("/largeIcon.png"));
	}

	private ResourceManager() {
		// static
	}

	/**
	 * Get a message by its key.
	 * @param key message key
	 * @return the message
	 */
	public static String getMsg(String key) {
		if (!messages.containsKey(key)) {
			throw new RuntimeException("No message for key: " + key);
		}
		return messages.get(key);
	}

	/**
	 * Get an icon by its key.
	 * @param key the icon key
	 * @return the icon
	 */
	public static Icon getIcon(String key) {
		if (!icons.containsKey(key)) {
			throw new RuntimeException("No icon for key: " + key);
		}
		return icons.get(key);
	}

	// load an Icon
	private static Icon icon(final String loc) {
		return new ImageIcon(Toolkit.getDefaultToolkit().createImage(
				ResourceManager.class.getResource(loc)));
	}

}
